#pragma once

#include "common_unit.h"
#include <butil/logging.h>

class MemoryUnit{
public:
    static MemoryUnit & Instance() {
        static MemoryUnit instance;
        return instance;
    }

    void Init(size_t size) {
        ptr = CommonUtils::prepare_host_memory(size);
        this->total_size = size;
        LOG(INFO) << "Malloc total size is " << size;
    }

    void * Malloc(size_t size) {
        void * ret_ptr = ptr + total_used_space;
        total_used_space += size; 
        return ret_ptr;
    }

public:
    void * ptr;
    size_t total_used_space = 0;
    size_t total_size;
};